package com.lj.demo.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lj.demo.commonutils.R;
import com.lj.demo.eduservice.entity.EduCourse;
import com.lj.demo.eduservice.entity.EduTeacher;
import com.lj.demo.eduservice.service.EduCourseService;
import com.lj.demo.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: liujiang
 * @Date: 2020/12/21/21:58
 * @Description:
 */
@Api(description = "查询前8条热门课程，查询前4条名师")
@CrossOrigin
@RestController
@RequestMapping("/eduservice/index")
public class IndexController {


    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @GetMapping("index")
    public R getCourseList(){
        //按id查询前八节课程
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        queryWrapper.last("limit 8");
        List<EduCourse> eduCourseList = courseService.list(queryWrapper);

        //按id查询前4名老师
        QueryWrapper<EduTeacher> queryWrapper1 = new QueryWrapper<>();
        queryWrapper1.orderByDesc("id");
        queryWrapper1.last("limit 4");
        List<EduTeacher> eduTeacherList = teacherService.list(queryWrapper1);

        return R.ok().data("courseList",eduCourseList).data("teacherList",eduTeacherList);


    }
}
